﻿///*
//  Source description:
//     This part of the source and the source network, and modify non-DBHelper.org site open source, source code using static methods in this section, you can easily perform some simple Sql statement.
// */
//using System;
//using System.Collections.Generic;
//using System.Text;
//using System.Data.OracleClient;
//using System.Data;
//using System.Configuration;
//using System.Collections;

//namespace Framework.Common.Sql
//{
//    public partial class OracleHelper
//    {
//        public static readonly string default_connection_str = ConfigurationManager.ConnectionStrings["OracleHelper"].ConnectionString;

//        private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());

//        public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            using (OracleConnection conn = new OracleConnection(connectionString))
//            {
//                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
//                int val = cmd.ExecuteNonQuery();
//                cmd.Parameters.Clear();
//                return val;
//            }
//        }

//        public static OracleConnection GetConnection()
//        {
//            return new OracleConnection(default_connection_str);
//        }

//        public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ExecuteNonQuery(default_connection_str, cmdType, cmdText, commandParameters);
//        }

//        public static int ExecuteNonQuery(string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ExecuteNonQuery(default_connection_str, CommandType.Text, cmdText, commandParameters);
//        }

//        public static int ExecuteNonQueryProc(string StoredProcedureName, params OracleParameter[] commandParameters)
//        {
//            return ExecuteNonQuery(default_connection_str, CommandType.StoredProcedure, StoredProcedureName, commandParameters);
//        }

//        public static int ExecuteNonQuery(OracleConnection connection, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
//            int val = cmd.ExecuteNonQuery();
//            cmd.Parameters.Clear();
//            return val;
//        }

//        public static int ExecuteNonQuery(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
//            int val = cmd.ExecuteNonQuery();
//            cmd.Parameters.Clear();
//            return val;
//        }

//        public static OracleDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            OracleConnection conn = new OracleConnection(connectionString);
//            try
//            {
//                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
//                OracleDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
//                cmd.Parameters.Clear();
//                return rdr;
//            }
//            catch
//            {
//                conn.Close();
//                throw;
//            }
//        }

//        public static OracleDataReader ExecuteReader(OracleConnection conn,string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ExecuteReader(default_connection_str, CommandType.Text, cmdText, commandParameters);
//        }

//        public static OracleDataReader ExecuteReader(string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ExecuteReader(default_connection_str, CommandType.Text, cmdText, commandParameters);
//        }

//        public static OracleDataReader ExecuteReaderProc(string StoredProcedureName, params OracleParameter[] commandParameters)
//        {
//            return ExecuteReader(default_connection_str, CommandType.StoredProcedure, StoredProcedureName, commandParameters);
//        }

//        public static OracleDataReader ExecuteReader(CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ExecuteReader(default_connection_str, cmdType, cmdText, commandParameters);
//        }
        
//        public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            using (OracleConnection connection = new OracleConnection(connectionString))
//            {
//                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
//                object val = cmd.ExecuteScalar();
//                cmd.Parameters.Clear();
//                return val;
//            }
//        }

//        public static object ExecuteScalar(string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ExecuteScalar(default_connection_str, CommandType.Text, cmdText, commandParameters);
//        }

//        public static object ExecuteScalarProc(string StoredProcedureName, params OracleParameter[] commandParameters)
//        {
//            return ExecuteScalar(default_connection_str, CommandType.StoredProcedure, StoredProcedureName, commandParameters);
//        }

//        public static object ExecuteScalar(CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ExecuteScalar(default_connection_str, cmdType, cmdText, commandParameters);
//        }

//        public static object ExecuteScalar(OracleConnection connection, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
//            object val = cmd.ExecuteScalar();
//            cmd.Parameters.Clear();
//            return val;
//        }
        
//        public static void CacheParameters(string cacheKey, params OracleParameter[] commandParameters)
//        {
//            parmCache[cacheKey] = commandParameters;
//        }

//        public static OracleParameter[] GetCachedParameters(string cacheKey)
//        {
//            OracleParameter[] cachedParms = (OracleParameter[])parmCache[cacheKey];
//            if (cachedParms == null)
//                return null;
//            OracleParameter[] clonedParms = new OracleParameter[cachedParms.Length];
//            for (int i = 0, j = cachedParms.Length; i < j; i++)
//                clonedParms[i] = (OracleParameter)((ICloneable)cachedParms[i]).Clone();
//            return clonedParms;
//        }

//        private static void PrepareCommand(OracleCommand cmd, OracleConnection conn, OracleTransaction trans, CommandType cmdType, string cmdText, OracleParameter[] cmdParms)
//        {
//            if (conn.State != ConnectionState.Open)
//                conn.Open();
//            cmd.Connection = conn;
//            cmd.CommandText = cmdText;
//            if (trans != null)
//                cmd.Transaction = trans;
//            cmd.CommandType = cmdType;
//            if (cmdParms != null)
//            {
//                foreach (OracleParameter parm in cmdParms)
//                    cmd.Parameters.Add(parm);
//            }
//        }




//        public static DataTable ReadTable(OracleTransaction transaction, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            PrepareCommand(cmd, transaction.Connection, transaction, cmdType, cmdText, commandParameters);
//            DataTable dt = HelperBase.ReadTable(cmd);
//            cmd.Parameters.Clear();
//            return dt;
//        }

//        public static DataTable ReadTable(string connectionString, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            using (OracleConnection connection = new OracleConnection(connectionString))
//            {
//                connection.Open();
//                return ReadTable(connection, cmdType, cmdText, commandParameters);
//            }
//        }
//        public static DataTable ReadTable(CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            return ReadTable(default_connection_str, cmdType, cmdText, commandParameters);
//        }

//        public static DataTable ReadTable(OracleConnection connection, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
//        {
//            OracleCommand cmd = new OracleCommand();
//            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
//            DataTable dt = HelperBase.ReadTable(cmd);
//            cmd.Parameters.Clear();
//            return dt;
//        }

//        public static OracleParameter CreateInputParameter(string paramName, OracleType dbtype, object value)
//        {
//            return CreateParameter(ParameterDirection.Input, paramName, dbtype, 0, value);
//        }
//        public static OracleParameter CreateInputParameter(string paramName, OracleType dbtype, int size, object value)
//        {
//            return CreateParameter(ParameterDirection.Input, paramName, dbtype, size, value);
//        }

//        public static OracleParameter CreateOutputParameter(string paramName, OracleType dbtype)
//        {
//            return CreateParameter(ParameterDirection.Output, paramName, dbtype, 0, DBNull.Value);
//        }

//        public static OracleParameter CreateOutputParameter(string paramName, OracleType dbtype, int size)
//        {
//            return CreateParameter(ParameterDirection.Output, paramName, dbtype, size, DBNull.Value);
//        }

//        public static OracleParameter CreateParameter(ParameterDirection direction, string paramName, OracleType dbtype, int size, object value)
//        {
//            OracleParameter param = new OracleParameter(paramName, dbtype, size);
//            param.Value = value;
//            param.Direction = direction;
//            return param;
//        }






//    }

//}
